package com.xiaoyi.library.mapper;

import com.xiaoyi.library.pojo.Book;
import org.apache.ibatis.annotations.*;
import org.springframework.web.bind.annotation.PostMapping;

import java.util.List;

@Mapper
public interface BookMapper {
    //查询book表的所有数据
    @Select("select * from book")
    public List<Book> find();
    //根据输入的书名到book表中进行查询
    @Select("SELECT * FROM book WHERE book_name LIKE CONCAT('%', #{book_name}, '%')")
    public List<Book> findByName(String book_name);
    //根据id删除
    @Delete("DELETE FROM book WHERE book_id = #{book_id}")
    boolean deleteById(int book_id);
    // 向book表中插入数据
    @Insert("INSERT INTO book (book_name, book_isbn, book_press, book_author, book_pagination, book_price, book_uploadtime, book_status) " +
            "VALUES (#{book_name}, #{book_isbn}, #{book_press}, #{book_author}, #{book_pagination}, #{book_price}, #{book_uploadTime}, '0')")
    boolean insert(Book book);
    @Update("UPDATE book SET book_name = #{book_name}, book_isbn = #{book_isbn}, book_press = #{book_press}, " +
            "book_author = #{book_author}, book_pagination = #{book_pagination}, book_price = #{book_price}, " +
            "book_uploadtime = #{book_uploadTime}, book_status = #{book_status} WHERE book_id = #{book_id}")
    boolean update(Book book);


}
